package com.willie.utils.sql.table;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * ----------------------------------------------
 * <p>类    名：</p>
 * <p>版    权：copyright© firegy.willie</p>
 * <p>作    者: liang</p>
 * <p>创建时间: 2018/6/4 21:40</p>
 * <p>描    述: </p>
 * <p>修 改 人：</p>
 * <p>修改时间：</p>
 * -----------------------------------------------
 */
public class Table implements Serializable {
    private static final long serialVersionUID = -6857513116523402413L;
    /**
     * 表名称
     */
    private String name;

    /**
     * 主键
     */
    private String primaryKey;

    /**
     * 记录数
     */
    private long recordCount;

    /**
     * 字段
     */
    private List<Field> Fields;

    /**
     * 行记录
     */
    private List<Map<String, String[]>> records;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(String primaryKey) {
        this.primaryKey = primaryKey;
    }

    public long getRecordCount() {
        return recordCount;
    }

    public void setRecordCount(long recordCount) {
        this.recordCount = recordCount;
    }

    public List<Field> getFields() {
        return Fields;
    }

    public void setFields(List<Field> fields) {
        Fields = fields;
    }

    public List<Map<String, String[]>> getRecords() {
        return records;
    }

    public void setRecords(List<Map<String, String[]>> records) {
        this.records = records;
    }

    /**
     * 字段
     */
    public static class Field {
        /**
         * 字段名称
         */
        private String name;

        /**
         * 字段类型
         */
        private String type;
        /**
         * 字段长度
         */
        private int precision;
        /**
         * 小数位
         */
        private int scale;
        /**
         * 是否允许为空
         */
        private boolean nullable;

        public Field(String name, String type, int precision, int scale, boolean nullable) {
            this.name = name;
            this.type = type;
            this.precision = precision;
            this.scale = scale;
            this.nullable = nullable;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getType() {
            return type;
        }

        public void setType(String type) {
            this.type = type;
        }

        public int getPrecision() {
            return precision;
        }

        public void setPrecision(int precision) {
            this.precision = precision;
        }

        public int getScale() {
            return scale;
        }

        public void setScale(int scale) {
            this.scale = scale;
        }

        public boolean isNullable() {
            return nullable;
        }

        public void setNullable(boolean nullable) {
            this.nullable = nullable;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Field field = (Field) o;
            return precision == field.precision &&
                    scale == field.scale &&
                    nullable == field.nullable &&
                    Objects.equals(name, field.name) &&
                    Objects.equals(type, field.type);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name, type, precision, scale, nullable);
        }

        @Override
        public String toString() {
            return "Field{" +
                    "name='" + name + '\'' +
                    ", type='" + type + '\'' +
                    ", precision=" + precision +
                    ", scale=" + scale +
                    ", nullable=" + nullable +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "Table{" +
                "name='" + name + '\'' +
                ", primaryKey='" + primaryKey + '\'' +
                ", recordCount=" + recordCount +
                ", Fields=" + Fields +
                ", records=" + records +
                '}';
    }
}
